<?php

require_once(DIR_LIB."VsCore".DIR_SEP."vssession.php");

class VsHtmlImagesFactory {

	private $_htmlImages = NULL;

	private static $_Instance = NULL;

	/* Modes
	*----------
	*	0 - For Register
	*	1 - For View
	*/
	static function Instance($mod=0) {
		if(!self::$_Instance)
			self::$_Instance = &new VsHtmlImagesFactory($mod);

		return self::$_Instance;
	}
	//========================================================

	private function __construct($mod){
		$session = VsSession::Instance();

		if(!$mod) {
			$session->assign('HtmlImages', array());
		}

		$this->_htmlImages = &$session->value('HtmlImages');
	}
	//========================================================

	function registerImage($image) {
		array_push($this->_htmlImages, $image);
		
		return count($this->_htmlImages)-1;
	}
	//========================================================

	function showImage($code) {
		$file = $this->_htmlImages[$code];
		$handle = finfo_open(FILEINFO_MIME);
		$mime_type = finfo_file($handle,$file);

		echo $file;
		echo $mime_type;

		header("Content-type: ".$mime_type);
        @include($file);
	}
	//========================================================

};

?>
